<?php

class OnlineHelp extends Portlet
{
    private $_controllerId;
    private $_controllerAction;
    private $_onlineHelpBookName = 'Online Help';
    private $_wikiBook;
    private $_wikiPages;
    // {{{ init
    public function init()
    {
        $this->title=CHtml::encode(Yii::t('site','Online Help'));
        $this->_wikiBook = WikiBook::model()->findByAttributes(array('name'=>$this->_onlineHelpBookName));

        $this->_controllerId        = Yii::app()->controller->id;
        $this->_controllerAction    = Yii::app()->controller->action->id;

        $criteria = new CDbCriteria;
        $criteria->compare('wikiBookId',$this->_wikiBook->id, false);
        $criteria->compare('tags','Action_'.$this->_controllerId.'_'.$this->_controllerAction, true);
        $this->_wikiPages = WikiPage::model()->findAll($criteria);
        if(count($this->_wikiPages)==0 and !Yii::app()->user->checkAccess('admin'))
            $this->visible = false;
        parent::init();
    } // }}} 
    // {{{ renderContent
    protected function renderContent()
    {
	$this->render(
	    'onlineHelp',
            array(
                'controllerId' => $this->_controllerId,
                'controllerAction' => $this->_controllerAction,
                'wikiBookId' => $this->_wikiBook->id,
		'wikiPages' => $this->_wikiPages
	    )
	);
    } // }}} 
}
